package binarytree;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * Created by byakuya on 2020/8/4
 */
public class Preorder {

    List<Integer> res = new ArrayList<>();

    public List<Integer> preorderTraversal(TreeNode root) {
        //递归
        preorder(root);
        return res;
    }

    public void preorder(TreeNode root){ //递归函数
        if (root == null) return;
        res.add(root.val);
        preorderTraversal(root.left);
        preorderTraversal(root.right);
    }
}
